package tp.pr5.gui;

import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;

import tp.pr5.Room;
import tp.pr5.RoomInfo;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class MapCell extends JButton{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private RoomInfo _habitacion;
	private JTextArea _roomTextField;
	private int _x=0;
	private int _y=0;
	public MapCell() {
		addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				
				
			}
		});
		
				
		
	}
	public MapCell(int x,int y, JTextArea roomTextField) {
		this.set_x(x);
		this.set_y(y);
		this._roomTextField=roomTextField;
		
		addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if (_habitacion!=null) {
					_roomTextField.setText(_habitacion.getDescription());
				}
				else hiddenMessage();
					
			}
		});
				
		
	}

	public int get_x()
	{
		return _x;
	}
	public void set_x(int _x)
	{
		this._x = _x;
	}
	public int get_y()
	{
		return _y;
	}
	public void set_y(int _y)
	{
		this._y = _y;
	}
	public void set_habitacion(RoomInfo targetRoom)
	{
		this._habitacion = targetRoom;
	}
	public void hiddenMessage() {
	JOptionPane.showMessageDialog(this,
			"Se desconoce lo que hay en ese cuarto.\nProbablemente una fregona.",
			"Cuarto desconocido", JOptionPane.QUESTION_MESSAGE);
	}
	public void update() {
		if (_habitacion!=null) {
			_roomTextField.setText(_habitacion.getDescription());
		}
	}
}